package com.holly.unit.deform.modular.controller;

import com.holly.unit.core.pojo.request.BaseRequest;
import com.holly.unit.core.pojo.response.ResponseData;
import com.holly.unit.core.pojo.response.SuccessResponseData;
import com.holly.unit.db.api.pojo.page.PageResult;
import com.holly.unit.deform.api.DeformTempletApi;
import com.holly.unit.deform.api.pojo.templet.DesignFormTempletDTO;
import com.holly.unit.deform.api.pojo.templet.DesignFormTempletRequest;
import com.holly.unit.deform.entity.DesignFormTemplet;
import com.holly.unit.deform.modular.pojo.DesignFormTemplatePackageOptionsRequest;
import com.holly.unit.deform.modular.pojo.DesignFormTempletQueryRequest;
import com.holly.unit.scanner.api.annotation.ApiResource;
import com.holly.unit.scanner.api.annotation.GetResource;
import com.holly.unit.scanner.api.annotation.PostResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 类描述: 表单设计器模板 控制器
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/4/11 13:32
 */
@Slf4j
@RestController
@ApiResource(name = "表单设计器模板表")
@Api(tags = "表单设计器模板表")
public class DeformTemplateController {

    @Resource
    private DeformTempletApi api;


    /**
     * 新增
     *
     * @param designFormTempletRequest
     * @return
     */
    @ApiOperation(value = "增加" ,notes = "增加")
    @PostResource(name = "增加", path = "/designFormTemplet/add", requiredPermission = false , requiredLogin = false)
    public ResponseData add(@RequestBody @Validated(BaseRequest.add.class) DesignFormTempletRequest designFormTempletRequest) {
        api.add(designFormTempletRequest);
        return new SuccessResponseData();
    }
    /**
     * 编辑
     * @param designFormTempletRequest
     * @author holly
     * @date 2022-03-03 03:36:38
     */
    @ApiOperation(value = "编辑" ,notes = "编辑")
    @PostResource(name = "编辑", path = "/designFormTemplet/edit", requiredPermission = false , requiredLogin = false)
    public ResponseData edit(@RequestBody @Validated(DesignFormTempletRequest.edit.class) DesignFormTempletRequest designFormTempletRequest) {
        api.edit(designFormTempletRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author holly
     * @date 2022-03-03 03:36:38
     */
    @ApiOperation(value = "删除" ,notes = "删除")
    @PostResource(name = "删除", path = "/designFormTemplet/delete", requiredPermission = false , requiredLogin = false)
    public ResponseData delete(@RequestBody @Validated(DesignFormTempletRequest.delete.class) DesignFormTempletRequest designFormTempletRequest) {
        api.del(designFormTempletRequest);
        return new SuccessResponseData();
    }
    /**
     * 详情
     *
     * @author holly
     * @date 2022-03-03 03:36:38
     */
    @ApiOperation(value = "详情" ,notes = "详情")
    @PostResource(name = "详情", path = "/designFormTemplet/detail", requiredPermission = false , requiredLogin = false)
    public ResponseData detail(@RequestBody @Validated(DesignFormTempletRequest.detail.class) DesignFormTempletRequest designFormTempletRequest) {
        DesignFormTempletDTO designFormTempletDTO = api.detail(designFormTempletRequest);
        return new SuccessResponseData(designFormTempletDTO);
    }

    /**
     * 导出
     *
     * @author holly
     * @date 2022-03-03 03:36:38
     */
    @ApiOperation(value = "导出" ,notes = "导出")
    @GetResource(name = "导出", path = "/designFormTemplet/export", requiredPermission = false , requiredLogin = false)
    public void export(HttpServletResponse response) {
        api.export(response);
    }

    /**
     * 分页列表查询
     *
     * @author holly
     * @date 2022-03-03 03:36:38
     */
    @ApiOperation(value = "分页查询" ,notes = "分页查询")
    @GetResource(name = "分页查询", path = "/designFormTemplet/page", requiredPermission = false , requiredLogin = false)
    public ResponseData page(DesignFormTempletRequest designFormTempletRequest) {
        return new SuccessResponseData(api.findPage(designFormTempletRequest));
    }

    /**
     * 列表查询
     *
     * @author holly
     * @date 2022-03-03 03:36:38
     */
    @ApiOperation(value = "列表查询" ,notes = "列表查询")
    @GetResource(name = "列表查询", path = "/designFormTemplet/list", requiredPermission = false , requiredLogin = false)
    public ResponseData list(DesignFormTempletRequest designFormTempletRequest) {
        return new SuccessResponseData(api.findList(designFormTempletRequest));
    }


    /**
     * 返回封装成可解析的options
     * @param request
     */
    @ApiOperation(value = "返回封装成可解析的options" ,notes = "返回封装成可解析的options")
    @GetResource(name = "返回封装成可解析的options" , path = "/designFormTemplet/packageOptions")
    public ResponseData queryAllList(DesignFormTemplatePackageOptionsRequest request) {
        List<Map<String, Object>> result = api.findAnalysisOptions(request.getLabel(), request.getValue(), request.getUseId(), request.getReturnJson());
        return new SuccessResponseData(result);
    }

    /**
     * 分页列表查询
     * @param designFormTemplet
     * @param req
     * @return
     */
    @ApiOperation(value = "分页列表查询" ,notes = "分页列表查询")
    @GetResource(name = "分页列表查询" , path = "/designFormTemplet/queryPageList")
    public ResponseData queryPageList(DesignFormTemplet designFormTemplet, HttpServletRequest req) {
        PageResult<DesignFormTemplet> page = api.page(designFormTemplet, req.getParameterMap());
        return new SuccessResponseData(page);
    }


    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "批量删除" ,notes = "批量删除")
    @PostResource(name = "批量删除" , path = "/designFormTemplet/deleteBatch")
    public ResponseData deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        api.delBatch(ids);
        return new SuccessResponseData();
    }


    /**
     * 通过code查询
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "通过code查询" ,notes = "通过code查询")
    @GetResource(name = "通过code查询" , path = "/designFormTemplet/queryByCode")
    public ResponseData queryByCode(@Validated(DesignFormTempletQueryRequest.queryByCode.class) DesignFormTempletQueryRequest request) {
        DesignFormTemplet designFormTemplet = (DesignFormTemplet) api.fetchEntityByCode(request.getCode());
        return  new SuccessResponseData(designFormTemplet);

    }

    /**
     * 通过id查询
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "通过id查询" ,notes = "通过id查询")
    @GetResource(name = "通过id查询" , path = "/designFormTemplet/queryById")
    public ResponseData queryById(@Validated(DesignFormTempletQueryRequest.queryById.class) DesignFormTempletQueryRequest request) {
        DesignFormTemplet designFormTemplet = (DesignFormTemplet) api.fetchEntityById(request.getId());
        return  new SuccessResponseData(designFormTemplet);
    }























}
